package rpg;

import java.awt.Insets;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.StringTokenizer;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class GameOver extends JDialog {
	private static final long serialVersionUID = 1L;
	private JLabel tekst;
	private JTextField imie;
	private JLabel wynik;
	private JButton ok;
	private int w;
	
	public GameOver(int w){
		this.w=w;
		setTitle("Koniec");
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setLayout(null);
		setSize(250, 150);
		setModal(true);
		setLocation(new Point(330, 220));
		setResizable(false);
		
		tekst=new JLabel("Podaj imie:");
		tekst.setBounds(30, 15, 70, 25);
		
		imie=new JTextField("");
		imie.setBounds(105, 15, 100, 25);
		
		wynik=new JLabel("Twoj wynik: "+w);
		wynik.setBounds(45, 50, 115, 25);
		
		ok=new JButton("OK");
		ok.setBounds(75, 85, 55, 30);
		ok.setFocusable(false);
		ok.setMargin(new Insets(1, 1, 1, 1));
		ok.addActionListener(new Koniec());
		
		add(ok);
		add(tekst);
		add(wynik);
		add(imie);
		setVisible(true);
	}
	

	
	private class Koniec implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent e) {
			if(!(imie.getText().equals("")))
				if(Character.isLetterOrDigit(imie.getText().charAt(0))){
	
					dispose();
				}else{
					imie.setText("Anonim");
				}
			
		}
	
	}

}